/** 
*** This javascript library is used to visualize the geometric configuration and 
*** highlight the objective objects which could be a geometric concept, conclusion, etc.
*/




var hcIndex = 0;

var hcTiming = null;

// timing the objective object
var objectiveTiming = new Array();

var colorPallet = new Array();

//constructor
function AutoShow(app, hc, hcArea, oc, ocn, ho, os, tip, interval){
	this.applet = app;
	this.hypothesisConstruction = hc;
	this.objectiveConstruction = oc;
	this.objectiveStatement = os;	
	this.hiddenObj = ho;
	this.hypothesisConstructionArea = hcArea;
	this.objectiveObjName = ocn;
	this.tip = tip;
	this.interval = interval;
}



//initial the instruction list

function currentStatement(commandNum, objectNum){

    var strState = "";
    for(i=commandNum; i<objectNum; i++){
        strState += generateStatement(i);
    }
    
    return strState;
}

function generateStatement(num){

    var strName = applet.getObjectName(num);
    var strType = applet.getObjectType(strName);
    var strDef = applet.getDefinitionString(strName);
    var strCommand = applet.getCommandString(strName);
    var object  = strType + " " + strName;
    var strState = object + ";";
    if(strDef != ""){
        if(strCommand!=""){
            strState = object + ",\ndefinition: " + strDef + ",\ncommand: " + strCommand + ";";
        }
        else{
            strState = object + ",\ndefinition: " + strDef + ";";
        }
    }else{
        if(strCommand!=""){
            strState = object + ",\ncommand: " + strCommand + ";";
        }
    
    }
    
    return "Step " + (num+1) + ": " + strState  + "\n---\n";

}




function autoDraw() {
  if(hcIndex < hypothesisConstruction.length){
  
        var startObjectNum = applet.getObjectNumber();
  
        applet.evalCommand(hypothesisConstruction[hcIndex]);

        var endObjectNum = applet.getObjectNumber();

        if(hcIndex==0){
            hypothesisConstructionArea.value = "------Start------\n";
        }
        var value = hypothesisConstructionArea.value;
				var currentValue = currentStatement(startObjectNum,endObjectNum);
        //output the instructions into the instruction list
        hypothesisConstructionArea.value = value + currentValue;
  			hypothesisConstructionArea.scrollTop=hypothesisConstructionArea.scrollHeight;	
  			
				//output the instructions into the instruction
				tip.value = currentValue;

        hcIndex++;
    
        hcTiming = setTimeout("autoDraw()", interval);
	}else{  
   
        clearTimeout(hcTiming);   //W"Rb:clearTimeout(hcTiming)1XPkN;SZsetTimeout()V.:s,2;D\JGV.G0,T-Rr:\H]RW_O!   
   
        hypothesisConstructionArea.value = hypothesisConstructionArea.value + "------End------";
   
    
	}
    

 setHypothesisFeel(applet);

}



    
function pause(){
        clearTimeout(hcTiming); 
		for(i=0;i<objectiveTiming.length;i++){
				clearTimeout(objectiveTiming[i].visibleTime);
				clearTimeout(objectiveTiming[i].unVisibleTime);
		}

    }
    
function restart(){
        applet.reset();
        hypothesisConstructionArea.value = "";  
        hcIndex=0;
        autoDraw();


    }
    
    
    
function previous(){
        
    }
    
function next(){
        
        
        
    }
	
	//the conclustion is the relation of two objects
	function objective(){

		tip.value = "Show: " + objectiveStatement;
		
		if(hiddenObj!=null){
			for(t=0;t<hiddenObj.length;t++){
				applet.setVisible(hiddenObj[t],false);
			}
		}
	
		if(objectiveConstruction!=null){
			for(i=0;i<objectiveConstruction.length;i++){
				applet.evalCommand(objectiveConstruction[i]);
			}
		}
		
		setObjectiveFeel();
		
			
	}
	
	
	
